package com.inter.law.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.inter.law.dao.IlCaseToClientDAO;
import com.inter.law.dao.IlDeptDAO;
import com.inter.law.dao.IlLawerDAO;
import com.inter.law.entity.IlLawer;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 人员选择
 * @author Administrator
 *
 */
public class ChoosePerson extends ActionSupport{
	private static final Integer many=1;//分页查询每页显示的条目的个数
	private Integer lawerDeptId;
	private String lawerName;
	private Integer pageIndex=1;
	private Integer total;//查询条目总数
	private Integer pagenumber;//总页数
	private ApplicationContext ctx = new ClassPathXmlApplicationContext(
			"applicationContext.xml");
	private List<String> lawerNames=new ArrayList<String>();
	private List<Integer> lawerIds=new ArrayList<Integer>();
	private List<Integer> lawerDeptIds=new ArrayList<Integer>();
	private List<String> deptNames=new ArrayList<String>();
	
	private Integer which;//页面上选择人员的地方有三块，1，2，3分别代表这三块
	private Integer index;//页面上同一块可能有多个地方需要选择人员，这里的index是指所在块的索引
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		IlLawerDAO ilLawerDAO =IlLawerDAO.getFromApplicationContext(ctx);
		if(total==null||total==0){
			total=ilLawerDAO.findByNameAndDeptTotal(lawerName, lawerDeptId);
			if(total%many==0){
				pagenumber=total/many;
			}else{
				pagenumber=total/many+1;
			}

		}
		List<IlLawer> list=ilLawerDAO.findByNameAndDept(lawerName, lawerDeptId, pageIndex, many);
		if(list!=null&&list.size()>0){
			for(int i=0;i<list.size();i++){
				lawerIds.add(list.get(i).getLawerId());
				lawerNames.add(list.get(i).getLawerName());
				lawerDeptIds.add(list.get(i).getLawerDeptId());
			}
			IlDeptDAO ilDeptDAO=IlDeptDAO.getFromApplicationContext(ctx);
			deptNames=ilDeptDAO.getNameListByIdList(lawerDeptIds);
		}
		System.out.println("AA");
		return SUCCESS;
	}
	public Integer getLawerDeptId() {
		return lawerDeptId;
	}
	public void setLawerDeptId(Integer lawerDeptId) {
		this.lawerDeptId = lawerDeptId;
	}
	public String getLawerName() {
		return lawerName;
	}
	public void setLawerName(String lawerName) {
		this.lawerName = lawerName;
	}
	public Integer getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}
	public Integer getTotal() {
		return total;
	}
	public void setTotal(Integer total) {
		this.total = total;
	}
	public Integer getPagenumber() {
		return pagenumber;
	}
	public void setPagenumber(Integer pagenumber) {
		this.pagenumber = pagenumber;
	}
	public List<String> getLawerNames() {
		return lawerNames;
	}
	public void setLawerNames(List<String> lawerNames) {
		this.lawerNames = lawerNames;
	}
	public List<Integer> getLawerDeptIds() {
		return lawerDeptIds;
	}
	public void setLawerDeptIds(List<Integer> lawerDeptIds) {
		this.lawerDeptIds = lawerDeptIds;
	}
	public List<String> getDeptNames() {
		return deptNames;
	}
	public void setDeptNames(List<String> deptNames) {
		this.deptNames = deptNames;
	}
	public static Integer getMany() {
		return many;
	}
	public List<Integer> getLawerIds() {
		return lawerIds;
	}
	public void setLawerIds(List<Integer> lawerIds) {
		this.lawerIds = lawerIds;
	}
	public Integer getWhich() {
		return which;
	}
	public void setWhich(Integer which) {
		this.which = which;
	}
	public Integer getIndex() {
		return index;
	}
	public void setIndex(Integer index) {
		this.index = index;
	}
	
	

}
